import os
from scipy import fft
import numpy as np
import csv
from tqdm import tqdm

originDataSetDir = "./DataSetProcess/MyValidation2017/"
outcomeDataSetDir = "./DataSetProcess/MyFFTValidation2017/"


if not os.path.exists(originDataSetDir):
    print("The orginal dataset directory is not exist!")
    exit(1)

if not os.path.exists(outcomeDataSetDir):
    os.makedirs(outcomeDataSetDir)


FFT_NUM = 10240
with open(originDataSetDir + "REFERENCE.csv") as csvfile:
    csv_reader = csv.reader(csvfile)  # 使用csv.reader读取csvfile中的文件
    pbar = tqdm(list(csv_reader))
    for i in pbar:
        filename = i[0]+".npy"
        data = np.load(originDataSetDir + filename)
        fft_data = abs(fft.fft(data, FFT_NUM)[FFT_NUM/2:])
        np.save(outcomeDataSetDir+filename, fft_data)
        pbar.set_description('Processing ' + filename)
